<?php
require '../com.swiss.mooh.dao.impl/FileDaoImpl.php';
require '../com.swiss.mooh.service/FileContentServiceImpl.php';



$dispatcher = new FileDaoImpl();
$fileContentService = new FileContentServiceImpl($dispatcher);

$output_dir = "../../assets/images/uploads/files/";

$fileName = $_POST['fileName'];
$descID = $_POST['descID'];
$filePath = $output_dir . $fileName;
if (file_exists($filePath)) {
    unlink($filePath);
    $result = $fileContentService->deleteFileContentByID($fileName);
    if ($result == 200) {
        $listOfFileVO = $fileContentService->getAllFileContentByDescID($descID);
        for ($i = 0; $i < $listOfFileVO->Size(); $i++) {
            ?>
            <a href="#" class="list-group-item">                                            
                <span class="badge" onclick="getLink('http://localhost/SwissMoohBackEnd/assets/images/uploads/files/<?= $listOfFileVO->GetObj($i)->getFileName(); ?>')"><i class="fa fa-link"></i></span>
                <span class="badge" onclick="deleteFileByName2('<?= $listOfFileVO->GetObj($i)->getFileName(); ?>', '<?= $descID ?>')"><i class="fa fa-trash"></i></span>
                <span><i class="fa fa-fw fa-calendar"></i> <?= $listOfFileVO->GetObj($i)->getFileName(); ?></span>
            </a>
            <?php
        }
    } else {
        echo $result;
    }
}
